package stark.app.function.imgedit;

import android.text.TextUtils;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.stark.imgedit.model.PhotoFrame;

import org.jetbrains.annotations.NotNull;

import stark.app.R;
import stark.app.databinding.ItemPhotoFrameBinding;
import stark.common.basic.adapter.BaseDBRVAdapter;
import stark.common.basic.utils.AssetUtil;

/**
 * Author：daizhongbin on 2021/5/31
 * Email：1027154338@qq.com
 * Desc:
 */
public class PhotoFrameAdapter extends BaseDBRVAdapter<PhotoFrame, ItemPhotoFrameBinding> {

    private int mSelPos = -1;

    public PhotoFrameAdapter() {
        super(R.layout.item_photo_frame, 0);
    }

    @Override
    public void onBindViewHolder(@NotNull BaseDataBindingHolder<ItemPhotoFrameBinding> holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.itemView.setSelected(mSelPos == position);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemPhotoFrameBinding> holder, PhotoFrame photoFrame) {
        super.convert(holder, photoFrame);
        ItemPhotoFrameBinding binding = holder.getDataBinding();
        if (TextUtils.isEmpty(photoFrame.getResName()) && photoFrame.getInfo() == null) {
            binding.ivImage.setImageResource(R.drawable.ic_photo_frame_none);
        } else {
            String filePath = AssetUtil.getFilePath("photoFrame", photoFrame.getResName());
            Glide.with(binding.ivImage).load(filePath).into(binding.ivImage);
        }
    }

    public void setSelPos(int selPos) {
        if (mSelPos != selPos) {
            mSelPos = selPos;
            notifyDataSetChanged();
        }

    }
}
